<?php
/**
 * this is cloud search http request class test file
 *
 *
 */
require_once 'index.php';
require_once 'Framework/TestCase.php';
class NonceTest extends PHPUnit_Framework_TestCase 
{
    const USER_ID = "123456789";
    const SCOPE   = "niced";

    public function testValidateString()
    {
        $nonce   = Nonce::generateString(self::USER_ID);
        $bool    = Nonce::validateString($nonce, self::USER_ID);
        $this->assertTrue($bool);
    }

    public function testCheckReplayAttack()
    {
        $time_interval = 1;
        $nonce = Nonce::generateString(self::USER_ID);
		$bool  = Nonce::checkReplayAttack($nonce, $time_interval);
        $this->assertTrue($bool);
		$bool  = Nonce::checkReplayAttack($nonce, $time_interval);
        $this->assertFalse($bool);
    }

    public function testCheckFlood()
    {
        $time_interval = 5;//s
        $max_count     = 1;

        $nonce = Nonce::generateString(self::USER_ID);
        $bool = Nonce::checkFlood(self::SCOPE, $time_interval, self::USER_ID, $max_count);
        $this->assertTrue($bool);
        $bool = Nonce::checkFlood(self::SCOPE, $time_interval, self::USER_ID, $max_count);
        $this->assertFalse($bool);
    }


    /**
     * execute before class
     *
     */
    public static function setUpBeforeClass()
    {

    }

    /**
     * execute before case
     *
     */
    protected function setUp()
    {

    }

    /**
     *
     * execute before assert
     */
    protected function assertPreConditions()
    {

    }

    /**
     *
     * execute after assert
     */
    protected function assertPostConditions()
    {

    }

    /**
     * execute after case
     */
    protected function tearDown()
    {

    }

    /**
     * execute after class
     *
     */
    public static function tearDownAfterClass()
    {

    }

}//end class
